<?php
class ARingBackSinger extends CActiveRecord
{
    public static function model($className = __CLASS__)
    {
        return parent::model ( $className );
    }
    // goi den bang can ket noi   
    public function tableName() 
    {                  
        return 'c_ring_singer';
    }  

    public function getDataById($singerId){ 
        $sql = "SELECT * FROM c_ring_singer WHERE id = ".$singerId;  
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $data = $command->queryRow();
        return $data;
    }      

    public function getAllData()
    {
        $sql = "SELECT * FROM c_ring_singer ORDER BY id DESC";
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $data = $command->queryAll();
        return $data;
    } 
    
    public function getAllSinger()
    {
        $sql = "SELECT id,name FROM c_ring_singer ORDER BY id DESC";
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $data = $command->queryAll();
        return $data;
    }  

    public function getAllNameSinger(){ 
        $sql = "SELECT * FROM c_ring_singer ORDER BY id DESC";
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $data = $command->queryAll();   
        return $data;
    } 

    public function getDataBySinger($id){ 
        $sql = "SELECT * FROM c_ring_singer WHERE id = ".$id;  
        $connect = Yii::app()->db;
        $command = $connect->createCommand($sql);
        $data = $command->queryRow();
        return $data;
    }   

    public function CheckSinger($name)
    {
        $sql = "SELECT count(id) FROM c_ring_singer WHERE name='" . mysql_escape_string($name) . "'";        
        $command = Yii::app()->db->createCommand($sql);
        $rows = $command->queryRow();
        return $rows["count(id)"];
    }
    
    public function CheckSingerEdit($name, $id)
    {
        $sql = "SELECT count(id) FROM c_ring_singer WHERE name='" . mysql_escape_string($name) . "' AND id!=" . $id;        
        $command = Yii::app()->db->createCommand($sql);
        $rows = $command->queryRow();
        return $rows["count(id)"];
    }
}
?>
